
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/27/2014 15:27:50
-- Generated from EDMX file: G:\CTYWX\Microhard.Protal\DataAccess\DBOfProtal.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Microhard_Product_Microhard_Category]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Microhard_Product] DROP CONSTRAINT [FK_Microhard_Product_Microhard_Category];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Microhard_Category]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Microhard_Category];
GO
IF OBJECT_ID(N'[dbo].[Microhard_Product]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Microhard_Product];
GO
IF OBJECT_ID(N'[dbo].[Microhard_SiteInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Microhard_SiteInfo];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Microhard_Product'
CREATE TABLE [dbo].[Microhard_Product] (
    [ProductID] uniqueidentifier  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Decription] nvarchar(max)  NOT NULL,
    [CreateTime] datetime  NULL,
    [CategoryID] uniqueidentifier  NULL,
    [SKU] nvarchar(50)  NULL
);
GO

-- Creating table 'Microhard_Category'
CREATE TABLE [dbo].[Microhard_Category] (
    [CategoryID] uniqueidentifier  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [CreationTime] datetime  NULL,
    [ParentCategoryID] uniqueidentifier  NULL,
    [CompanyID] uniqueidentifier  NULL
);
GO

-- Creating table 'Microhard_SiteInfo'
CREATE TABLE [dbo].[Microhard_SiteInfo] (
    [DataID] uniqueidentifier  NOT NULL,
    [Key] nvarchar(50)  NULL,
    [Value] nvarchar(max)  NULL,
    [CreationTime] datetime  NULL,
    [CompanyID] uniqueidentifier  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ProductID] in table 'Microhard_Product'
ALTER TABLE [dbo].[Microhard_Product]
ADD CONSTRAINT [PK_Microhard_Product]
    PRIMARY KEY CLUSTERED ([ProductID] ASC);
GO

-- Creating primary key on [CategoryID] in table 'Microhard_Category'
ALTER TABLE [dbo].[Microhard_Category]
ADD CONSTRAINT [PK_Microhard_Category]
    PRIMARY KEY CLUSTERED ([CategoryID] ASC);
GO

-- Creating primary key on [DataID] in table 'Microhard_SiteInfo'
ALTER TABLE [dbo].[Microhard_SiteInfo]
ADD CONSTRAINT [PK_Microhard_SiteInfo]
    PRIMARY KEY CLUSTERED ([DataID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CategoryID] in table 'Microhard_Product'
ALTER TABLE [dbo].[Microhard_Product]
ADD CONSTRAINT [FK_Microhard_Product_Microhard_Category]
    FOREIGN KEY ([CategoryID])
    REFERENCES [dbo].[Microhard_Category]
        ([CategoryID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Microhard_Product_Microhard_Category'
CREATE INDEX [IX_FK_Microhard_Product_Microhard_Category]
ON [dbo].[Microhard_Product]
    ([CategoryID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------